import java.util.Scanner;

public class NGuessNumber {

    private static int[] key = generateAnswer();

    /**
     * 生成四个不重复的0-9的数字
     */
    public static int[] generateAnswer() {
        int[] arr = new int[4];
        int a =0;
        while (a<4){
            boolean b=true;
            //创建随机数
            int random=(int) (Math.random()*10);
            for (int i = 0; i <arr.length ; i++) {
                if (random ==arr[i]){
                    b=false;
                    break;
                }
            }
            if (b){
                arr[a]=random;
                a++;
            }
        }
        return arr;
    }

    /**
     * 用户输入方法
     */
    public static int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("每个数字请用空格隔开");
        String s = scanner.nextLine();
        String[] split = s.split(" ");
        int [] player=new int[4];
        for (int i = 0; i < split.length; i++) {
            player[i]=Integer.parseInt(split[i]);
        }
        return player;
    }

    /**
     * 比较答案
     */
    public static int  compareGuessAnswer(int []c,int []key){
        int a,b;
        a=0;b=0;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < key.length ; j++) {
                if (c[i]==key[j]){
                    if (i==j) a++;
                    else b++;
                }
            }
        }
        System.out.println(a + " A "+b+" B");
        return a;
    }

    /**
     * 判断游戏有没有胜利
     */
    public static boolean isWin(int a){
        boolean boo=false;
        if (a==4){
            boo=true;
        }
        return boo;
    }
    public static void main(String[] args) {

        while (true){
            Scanner sc = new Scanner(System.in);
        while (true){
            int [] a =getPlayerInput();
            int aa =compareGuessAnswer(a,key);
            boolean b = isWin(aa);
            if (b){
                System.out.println("恭喜您猜对了！！！！");
                break;
            }
        }
            System.out.println("还要再晚上一盘码，侠士！(输入N推出，任意键继续)");
            String s = sc.next();
            if (s.equals("N")||s.equals("n")){
                break;
            }
            key=generateAnswer();
        }
    }

}
